package com.mobile.challenge.ui.report.unit.admin.adapter

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.mobile.challenge.ui.report.adapter.IRefresh
import java.util.*
import kotlin.collections.ArrayList

/**
 * @Author Touge
 * @Date 2020/9/16 21:34
 * @Description
 */
class AdminMoreFragmentAdapter(fragment: Fragment) : FragmentStateAdapter(fragment),
        IRefresh {

    var fragmentList = ArrayList<Fragment>(0)
        set(value) {
            field = value
            notifyDataSetChanged()
        }

    override fun getItemCount(): Int {
        return fragmentList.size
    }

    override fun createFragment(position: Int): Fragment {
        return fragmentList[position]
    }

    override fun refresh(calendar: Calendar, period: Int) {
        for (fragment in fragmentList) {
            if (fragment is IRefresh) {
                fragment.refresh(calendar, period)
            }
        }
    }
}